package com.jichangxiu.framework.utils;

import org.springframework.stereotype.Service;

@Service("jcx")
public class PermissionUtils {

    public boolean hasPower(String power) {
        return AuthUtils.hasPower(power);
    }

    public boolean hasPowerAnd(String... powers) {
        boolean flag = true;
        for (String power : powers)
            if (!hasPower(power)) flag = false;
        return flag;
    }

    public boolean hasPowerOr(String... powers) {
        boolean flag = false;
        for (String power : powers)
            if (hasPower(power)) {
                flag = true;
                break;
            }
        return flag;
    }

    public boolean hasRole(String role) {
        return AuthUtils.hasRole(role);
    }

    public boolean hasRoleAnd(String... roles) {
        boolean flag = true;
        for (String role : roles)
            if (!hasRole(role)) flag = false;
        return flag;
    }

    public boolean hasRoleOr(String... roles) {
        boolean flag = false;
        for (String role : roles)
            if (hasRole(role)) {
                flag = true;
                break;
            }
        return flag;
    }

    public boolean hasPost(String post) {
        return AuthUtils.hasPost(post);
    }

    public boolean hasPostAnd(String... posts) {
        boolean flag = true;
        for (String post : posts)
            if (!hasPost(post)) flag = false;
        return flag;
    }

    public boolean hasPostOr(String... posts) {
        boolean flag = false;
        for (String post : posts)
            if (hasPost(post)) {
                flag = true;
                break;
            }
        return flag;
    }

}
